<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>社交媒体</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
	<link href="<%=basePath%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/animate.min.css" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="<%=basePath%>/hplus/css/s_style.css" rel="stylesheet">
     <link rel="stylesheet" type="text/css" href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">
    
    <style>
        .s_box{
            width: 260px;
            height:200px;
            background: #fff;
            text-align: center;
            float: left;
            margin: 20px 20px 0 0;
        }
        .s_box > img{
            margin: 40px 0 20px;
        }
        .s_box_detailed{
            position: relative;
        }
        .s_box_detailed > img{
            position: absolute;
            right: 0;
            top: 0;
            margin: 0;
        }
        .s_time{
            height: 50px;
            line-height: 50px;
            border-top: 1px solid #ddd;
            text-align: left;
            padding: 0 16px;
        }
        .s_time a{
            float: right;
        }
        #authType{
        	visibility:hidden;
        }
    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="ibox-content">
             <span class="text-navy" style="font-size:22px;">1</span>个社交媒体
        </div>
        <div class="s_box" id="wxAuthDiv" hidden="">
            <img src="<%=basePath%>/hplus/img/wx.png" /><br />
            <button id="wechatAuth" class="btn btn-primary" type="button">微信授权</button>
        </div>
        <%-- <div class="s_box" id="auth_box">
            <img src="<%=basePath%>/hplus/img/wb.png" /><br />
            <button id="bind_weibo" class="btn btn-primary" type="button">微博授权</button>
            <br/>
        </div> --%>
        <div id="authInfoShow" class="s_box s_box_detailed" hidden="">
            <img src="<%=basePath%>/hplus/img/wx_icon.png" />
            <div class="col-sm-12" style="margin-top:50px;">
                <div class="col-sm-5">
                    <div class="text-center">
                        <img id="headImg" alt="image" class="img-circle m-t-xs img-responsive" src="<%=basePath%>/hplus/img/a2.jpg">
                        <!-- <div id="nickName" class="m-t-xs font-bold">CTO</div> -->
                    </div>
                </div>
                <div class="col-sm-7" style="text-align:left;">
                    <h3><strong id="nickName">传播西藏</strong></h3>
                    <p id="serviceTypeInfo">认证服务号</p> 
                    <p id="fansNum">关注用户:0</p>                        
                </div>
                <div class="clearfix"></div> 
            </div>
            <div class="clearfix"></div> 
            <div class="s_time col-md-12">
                <h5 id="authDay" class="col-md-6" style="margin-top:18px">已授权：0天</h5>
                <%-- <a href="javascript:deleteAuth();" style="margin-top: 15px;"><img src="<%=basePath%>/hplus/img/delete.png" /></a> --%>
                <a href="javascript:refreshBusinessAuthInfo();" style="margin-top: 15px;"><img src="<%=basePath%>/images/marketing/refresh.png" /></a>
              
            </div>
           <%--  <p class="s_time">已授权：100天
                <a href="javascript:;" style="margin-top: 15px;"><img src="<%=basePath%>/hplus/img/delete.png" /></a>
                <a href="javascript:;" style="margin-right:30px;margin-top: 15px;"><img src="<%=basePath%>/hplus/img/refresh.png" /></a>
            </p> --%>
        </div>
        <input type="hidden" id="bind_status" value="${sessionScope['org.springframework.web.servlet.support.SessionFlashMapManager.FLASH_MAPS'][0]['error_code']}"/>
        
        <%-- <div class="s_box s_box_detailed" id="userInfo_box" style="display: none;">
            <img src="<%=basePath%>/hplus/img/wb_icon.png" />
            <div class="col-sm-12" style="margin-top:50px;">
                <div class="col-sm-4">
                    <div class="text-center">
                        <img id="userHeader" alt="image" class="img-circle m-t-xs img-responsive" src="<%=basePath%>/hplus/img/a2.jpg">
                    </div>
                </div>
                <div class="col-sm-8" style="text-align:left;">
                    <h3 style="margin-top: 20px;"><strong id="nickName"></strong></h3>
<!--                     <p id="authType" style="color:#fff">微博</p> -->
<!--                     <p id="fansNum"></p>                         -->
                </div>
                <div class="clearfix"></div> 
            </div>
            <div class="clearfix"></div> 
            <p class="s_time">
            	过期日期：<span id="expireDate"></span>
            	<a onclick="removeBind()" href="javascript:;" style="margin-top: 12px;"><img src="<%=basePath%>/hplus/img/delete.png" /></a>
            </p>
        </div> --%>
    </div>
    <script src="<%=basePath%>/hplus/js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=basePath%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
    <script type="text/javascript" src="<%=path%>/js/dateUtils.js"></script> 
        <script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-loading-overlay/2.1.3/loadingoverlay.min.js"></script>
	<script type="text/javascript">
	   var path = "<%=path%>";
	   var state="";
	   var cid ;
	   $(function(){
		   cid=getQueryString("cid");
		   state=getQueryString("state");
		   // 初始化loading配置
		  $.LoadingOverlaySetup({
			    image       : '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000"><circle r="80" cx="500" cy="90"/><circle r="80" cx="500" cy="910"/><circle r="80" cx="90" cy="500"/><circle r="80" cx="910" cy="500"/><circle r="80" cx="212" cy="212"/><circle r="80" cx="788" cy="212"/><circle r="80" cx="212" cy="788"/><circle r="80" cx="788" cy="788"/></svg>',
			    imageColor  : "#1ab394",
			    maxSize : "50",
			});
		   // 如果是授权成功后回来 那么延迟3秒后执行查询粉丝信息
		   if(StringEmpty(state) && state == "success"){
			   setTimeout(function () { getBusinessAuthInfo(); }, 3000);
			   updateWechatAuth();
		   }else if(StringEmpty(state) && state == "unValidAuth"){
			   errorDialog("授权失败","请使用微信认证服务号授权！");
			   $('#wxAuthDiv').show();
           	   $('#authInfoShow').hide();
		   }else if(StringEmpty(state) && state == "fail"){
			   errorDialog("授权失败");
			   $('#wxAuthDiv').show();
           	   $('#authInfoShow').hide();
		   }else{
			   getBusinessAuthInfo();
		   }
	   });
	   
	   $(document).on("click", "#wechatAuth", function () {
		   getBusinessPreAuthUrl();
	   });
	   
	   /* 获取商家授权信息 */
	   function getBusinessAuthInfo(){
		   $.LoadingOverlay("show");
		   var url = "${pageContext.request.contextPath}/api/auth/getBusinessAuthInfo";
	        $.post(url, {
	            "cid": cid,
	        }, function (data) {
	            if (data.status == "200") {
	            	$('#authInfoShow').show();
	            	var wxAuthInfo = data.data;
                    initView(wxAuthInfo);
	            } else {
	            	$('#wxAuthDiv').show();
	            	$('#authInfoShow').hide();
	            }
	            $.LoadingOverlay("hide");
	        });
	   }
	   /* 获取授权url */
	   function getBusinessPreAuthUrl(){
		   var url = "${pageContext.request.contextPath}/api/auth/getBusinessPreAuthUrl";
	        $.post(url, {
	        }, function (data) {
	            if (data.status == "200") {
	            	window.location.href=data.data;
	            } else {
	            	errorDialog("获取授权失败");
	            }
	        });
	   } 
	   /* 更新shiro中商家有全员营销权限 */
	   function updateWechatAuth(){
		   var url = "${pageContext.request.contextPath}/api/auth/updateWechatAuth";
	        $.post(url, {
	        }, function (data) {
	        	
	        });
	   }
	   /* 删除授权 */
	   function deleteAuth(){
        	swal({
				  title: '删除确认',
				  text: "删除后酷客平台设置的公众号管理功能将失效，确定要删除吗？",
				  type: 'warning',
				  showCancelButton: true,
				  confirmButtonColor: '#1ab394',
				  cancelButtonColor: '#E8E8E8',
				  confirmButtonText: '确认',
				  cancelButtonText:'取消',
				  reverseButtons : true
				}).then(function () {
					var url = "${pageContext.request.contextPath}/api/auth/deleteAuth";
			        $.post(url, {
			        }, function (data) {
			            if (data.status == "200") {
			            	$('#wxAuthDiv').show();
			            	$('#authInfoShow').hide();
			            	successDialog("删除成功");
			            } else {
			            	errorDialog("删除失败");
			            }
			        });
				})
	   }

       /* 删除授权 */
       function refreshBusinessAuthInfo(){
           swal({
               title: '同步确认',
               text: "将公众号信息同步至酷客平台，一小时内只能进行一次，确定要同步吗？",
               type: 'warning',
               showCancelButton: true,
               confirmButtonColor: '#1ab394',
               cancelButtonColor: '#E8E8E8',
               confirmButtonText: '确认',
               cancelButtonText:'取消',
               reverseButtons : true
           }).then(function () {
               var url = "${pageContext.request.contextPath}/api/auth/refreshBusinessAuthInfo";
               $.post(url, {
                   "cid": cid,
               }, function (data) {
                   if (data.status == "200") {
                       var wxAuthInfo = data.data;
                       initView(wxAuthInfo);
                       successDialog("刷新成功");
                   } else {
                       errorDialog(data.message);
                   }
               });
           })
       }

       function initView(wxAuthInfo){
           $('#headImg').attr('src',wxAuthInfo.headImg);
           $('#principalName').html(wxAuthInfo.principalName);
           $('#nickName').html(wxAuthInfo.nickName);
           $('#fansNum').html("关注用户:"+wxAuthInfo.fanTotal);
           $('#authDay').html("已授权："+dateDiff(wxAuthInfo.createTime,new Date())+"天");
           var serviceTypeInfo= wxAuthInfo.serviceTypeInfo;
           var verifyTypeInfo= wxAuthInfo.verifyTypeInfo;
           if(serviceTypeInfo == 2 ){
               if(verifyTypeInfo == -1){
                   $('#serviceTypeInfo').html("普通服务号");
               }else{
                   $('#serviceTypeInfo').html('认证服务号<img id="authIcon" style="width:15px;height:15px;margin-left:3px;margin-bottom: 2px;" src="<%=basePath%>/images/marketing/auth_icon.png">');
                   $('#authIcon').show();
               }
           }else{
               if(verifyTypeInfo == -1){
                   $('#serviceTypeInfo').html("普通订阅号");
               }else{
                   $('#serviceTypeInfo').html('认证订阅号<img id="authIcon" style="width:15px;height:15px;margin-left:3px;margin-bottom: 2px;" src="<%=basePath%>/images/marketing/auth_icon.png">');
                   $('#authIcon').show();
               }
           }
       }
	</script>
	    
	    
	<script type="text/javascript">


    </script>
</body>
</html>